#ifndef _GRASS_LOADER_
#define _GRASS_LOADER_

#include "FEngineType.h"
#include "Node.h"
#include "PagedEntity.h"
#include "QuadTreeManager.h"
#include <vector>

#define _GRASS_LOADER_DEBUG_

namespace FEngine
{
	class PagedBillboardBlock;

	/**
	 * Handle the pagination of one billboard.
	 * One instance of the object is first created,
	 * then each instance of the object is set and render.
	 */
	class GrassLoader
	{

		public:

			/**
			 * Constructor.
			 * @param _blockSize Size of one page.
			 * @param _viewRange Distance of viewing.
			 */
			GrassLoader(float _blockSize, float _viewRange);
			~GrassLoader();
			
			/**
			 * Create the instance of the billboard to replicate.
			 * @param _textureName Name of the texture file of the billboard.
			 */
			void createBillboard(const std::string& _textureName);
			
			/**
			 * Add one instance of the billboard to the scene.
			 * @param _pos Position of the billboard.
			 * @param _sca Scale of the object.
			 * @param _windForce Amplitude of the movement of the billboard.
			 * @param _windOffset Offset of the movement of the wind.
			 */
			void addBillboard(const Vector3& _pos, const Vector3& _sca, float _windForce, float _windOffset);

			int	getNumberPage() const;
			int	getNumberVisiblePage() const;
			
			int	getNumberObject() const;
			int	getNumberVisibleObject() const;

			/**
			 * Count the number of object of the tree.
			 * Call this one tim eafter finishing adding every object to the GrassLoader.
			 */
			void calculateStats();
			
			void update(double _elapsedTime);
			void render(double _elapsedTime);

		private:

			LPDIRECT3DVERTEXBUFFER9			mVertexBuffer;
			IDirect3DVertexDeclaration9*	mVertexDeclaration;
			LPDIRECT3DINDEXBUFFER9			mIndexBuffer;
			LPDIRECT3DTEXTURE9				mBillboardTexture;
			
			int								mNumberVertices;
			int								mNumberPrimitives;
			
			float							mBlockSize;
			float							mMaximumViewDistance;
			QuadTreeManager*				mQuadTreeManager;
			
			int								mNumberPage;
			int								mNumberObject;

			
			void _setBuffers();
	};

} // namespace FEngine

#endif
